package com.zhongwang.business.module.basic.controller;

import com.zhongwang.business.base.BaseController;
import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.module.basic.service.SellerBasicService;
import com.zhongwang.business.gen.entity.SellerInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
public class SellerController extends BaseController {


    @Autowired
    private SellerBasicService sellerBasicService;

    /**
     * 首页跳转至卖家信息页面
     *
     * @param model
     * @return
     */
    @GetMapping("/basic/seller")
    @RequiresPermissions({"basic:seller:view"})
    public String sellerPage(Model model) {
        return "/basicManage/seller/page";
    }


    /**
     * 获取列表
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/sellerList")
    public JsonResult selectAllList(String sellerName) {
        startPage();
        List<SellerInfo> list = sellerBasicService.selectList(sellerName);
        return jsonResult(list);
    }


    @ResponseBody
    @PostMapping("/sellerSave")
    public JsonResult save(SellerInfo sellerInfo) {
        return isNotNull(sellerBasicService.saveSeller(sellerInfo));
    }

    @ResponseBody
    @PostMapping("/sellerUpdate")
    public JsonResult update(SellerInfo sellerInfo) {
        return isNotNull(sellerBasicService.updateSeller(sellerInfo));
    }

    @ResponseBody
    @GetMapping("/sellerDelete")
    public JsonResult delete(int id) {
        return isNotNull(sellerBasicService.deleteSeller(id));
    }





}